<?php

namespace app\index\controller;

use app\admin\model\Article;
use app\admin\model\Banner;
use app\admin\model\Category;
use app\admin\model\Course;
use app\common\controller\Frontend;

/**
 * create by PhpStorm 2025/3/8 14:48
 * guopin.com app\index\controller@Cate
 * 行止之行 <xingzhi8711@gmail.com>
 * 内容
 */
class Cate extends Frontend
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    private $cateMap=array(
        '14'=>"zpzx",
        '15'=>'qzfw',
        '16'=>'mstd',
        '17'=>'xyzp',
        '18'=>'gywm'
    );

    public function _initialize()
    {
        parent::_initialize();
        $bannerList=Banner::where('plat','pc')->where('status','normal')->order('id desc')->select();
        $this->assign('bannerList',$bannerList);
        $category=Category::get($this->cateId);

        $title=$category?$category->name:"";
        $this->assign("title",$title);
        $list="";
        if(in_array($this->cateId,[14,17])){
            $list=Article::where('category_id',$this->cateId)->order('id desc')->paginate(15);
        }
        if($this->cateId==18){
            $list=Article::where('category_id',$this->cateId)->find();
        }
        $courseList1=Course::where('category_id',19)->field('id,pro_json,keyword,title,image')->order('weigh desc')->limit(4)->select();
        $this->assign("courseList1",$courseList1);
        $courseList2=Course::where('category_id',20)->field('id,pro_json,keyword,title,image')->order('weigh desc')->limit(4)->select();
        $this->assign("courseList2",$courseList2);
        $this->assign("list",$list);
    }
    public function index()
    {
        return $this->fetch($this->cateMap[$this->cateId]);

    }

    public function detail()
    {
        $this->cateId=17;
        $this->assign('c',$this->cateId);
        $id=input('a',0);
        $detail=Article::get($id);
        if(!$detail) $this->error('内容不存在');
        $this->assign('detail',$detail);
        $this->assign('title',$detail->title);
        return $this->fetch();

    }
}